using System;
using System.Collections.Generic;
using Core.Domain.Bases;
using Core.Domain.Enums;

namespace Core.Domain.Entities
{
  ///<summary>Permanent record of election, kept in the Community database</summary>
  public class Election : EntityBaseWithId
  {
    public Election()
    {
      VoteRecipients = new List<VoteRecipient>();
      Voters = new List<Voter>();
    }

    ///<summary>When did this election take place?</summary>
    public virtual DateTime ElectionDate { get; set; }

    ///<summary>The type of this election</summary>
    public virtual ElectionType ElectionType { get; set; }

    ///<summary>For what community?</summary>
    public virtual Community InCommunity { get; set; }

    ///<summary>Voters casting ballots at the election</summary>
    public virtual IList<Voter> Voters { get; set; }

    // TODO: glittle 2009-04-11 - Add stats records

    ///<summary>List of the people actually elected</summary>
    public virtual IList<VoteRecipient> VoteRecipients { get; set; }
    
  }

  ///<summary>Adders for this class</summary>
  public static partial class Extensions
  {
    ///<summary>Add a VoteRecipient to this Election</summary>
    ///<param name="election"></param>
    ///<param name="voteRecipient"></param>
    public static Election Add(this Election election, VoteRecipient voteRecipient)
    {
      voteRecipient.InElection = election;
      election.VoteRecipients.Add(voteRecipient);
      return election;
    }

    ///<summary>Add a Voter to this Election</summary>
    ///<param name="election"></param>
    ///<param name="voter"></param>
    public static Election Add(this Election election, Voter voter)
    {
      voter.Election = election;
      election.Voters.Add(voter);
      return election;
    }

  }
}